package com.example.describe.service.serviceImpl;

import com.example.classsify.pojo.Classsify;
import com.example.commons.utils.MyPageHelper;
import com.example.commons.utils.OssUtil;
import com.example.commons.utils.PageResult;
import com.example.describe.mapper.DescribeMapper;
import com.example.describe.pojo.Describe;
import com.example.describe.service.DescribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class DescribeServiceImpl  implements DescribeService {


    @Autowired
    DescribeMapper describeMapper;

    @Autowired
    OssUtil ossUtil;

    @Override
    public PageResult DescribeList(String brandName, PageResult pageResult) {
        MyPageHelper.startPage(pageResult);
        Example example = new Example(Describe.class);
        example.createCriteria()
                .andLike("brandName", "%" + brandName + "%")
                .andEqualTo("delFlag",0);
        List<Describe> describes = describeMapper.selectByExample(example);
        return MyPageHelper.getPageResult(describes);
    }

    @Override
    public int Describeinfo(Describe describe, MultipartFile file) {
        if(file != null){
            String s = ossUtil.uploadFile(file);
            describe.setLogoUrl(s);
        }
        System.out.println("describe::"+describe );
        Date date = new Date();
        describe.setUpdateTime(date);
        if (describe.getId() != null && describe.getId() > 0) {
            // 修改
            int i = describeMapper.updateByPrimaryKeySelective(describe);
            return i;
        } else {
            // 添加
            describe.setCreateTime(date);
            describe.setDelFlag("0");
            int i = describeMapper.insertSelective(describe);
            return i;
        }
    }

    /**
     * @Author 小江
     * @Description //TODO 品牌删除
     * @Date 14:51 2022/11/16
     **/
    @Override
    public int Describe(Integer id) {
        Describe describe = new Describe();
        describe.setId(id);
        describe.setDelFlag("1");
        int i = describeMapper.updateByPrimaryKeySelective(describe);
        return i;
    }
}
